<?php global $has_permit; ?>
    <form action="<?php echo site_url('admin/site/user/index', true); ?>" method="post" id="frm_user_search">
    <?php if ($has_permit) :?>
    <div class="std_header auto_height">
        <div class="left">
            <strong><?php echo $module['title']; ?></strong>
        </div>
        <div class="right">
            <?php if ($has_privilege_new) :?>
            <button type="button" class="gray_btn" onclick="window.location='<?php echo site_url('admin/site/user/edit', true); ?>'"><span>Thêm mới</span></button>
            <?php endif; ?>
        </div>
    </div>
    <div class="std_header auto_height search_header ">
        <div class="std" align="center">
            <span class="span_filter">
                <label>ID:</label>
                <input placeholder="ID" type="text" class="small_filter" name="filters[id]" title="Tìm kiếm theo id người dùng" value="<?php echo isset($filters['id']) ? $filters['id'] : '' ;?>" />
            </span>
            <span class="span_filter">
                <label>Tên đăng nhập:</label>
                <input placeholder="Tên" style="width: 150px;" type="text" class="small_filter" name="filters[username]" title="Tìm kiếm theo tên đăng nhập" value="<?php echo isset($filters['username']) ? $filters['username'] : '' ; ?>" />
            </span>
            <span class="span_filter">
                <label>Email:</label>
                <input placeholder="Email" style="width: 150px;" type="text" class="small_filter" name="filters[email]" title="Tìm kiếm theo email người dùng" value="<?php echo isset($filters['email']) ? $filters['email'] : '' ; ?>" />
            </span>
            <span class="span_filter">
                <select name="filters[user_type]" style="width: 130px;">
                    <option value="0">Loại người dùng</option>
                    <option value="1" <?php if(isset($filters['user_type']) && $filters['user_type'] == 1):?> selected="selected" <?php endif ;?>>Tra cứu</option>
                    <option value="2" <?php if(isset($filters['user_type']) && $filters['user_type'] == 2):?> selected="selected" <?php endif ;?>>Nghiên cứu</option>
                    <option value="3" <?php if(isset($filters['user_type']) && $filters['user_type'] == 3):?> selected="selected" <?php endif ;?>>Chuyên gia</option>
                </select>
            </span>
            <span class="span_filter">
                <select name="filters[is_active]" style="width: 120px;">
                    <option value="0">Trạng thái</option>
                    <option value="1" <?php if(isset($filters['is_active']) && $filters['is_active'] == 1):?> selected="selected" <?php endif ;?>>Chưa kích hoạt</option>
                    <option value="2" <?php if(isset($filters['is_active']) && $filters['is_active'] == 2):?> selected="selected" <?php endif ;?>>Đã kích hoạt</option>
                </select>
            </span>
            <span class="span_filter" style="margin-left: 142px;">
                <label>Ngày tạo:</label>
                <input name="filters[created_at_from]" placeholder="Từ" type="text" class="date_picker" style="width: 150px;" value="<?php echo $filters['created_at_from']; ?>" />
                <input name="filters[created_at_to]" placeholder="Đến" type="text" class="date_picker" style="margin-left: 60px; width: 150px;" value="<?php echo $filters['created_at_to']; ?>" />
            </span>
            <span class="span_filter">
                <button type="button" class="gray_btn" style="margin-left:10px;position:relative;top:2px" onclick="return admin_user.act_filter()">
                    <span>Tìm</span>
                </button>
                &nbsp;
                <button type="button" class="gray_btn" style="position:relative;top:2px" onclick="return admin_user.reset_filters('frm_user_search')">
                    <span>Xóa lọc</span>
                </button>
            </span>
        </div>
    </div>
    <div id="user_management">
        <?php if (count($collection) != 0) : ?>
        <?php $paginator = $this->load->view('site/user/paginator', null, true); echo $paginator; ?>
        <?php endif; ?>
        <input type="hidden" name="current_page" id="current_page" value="<?php echo $current_page; ?>" />

        <?php $this->load->view('site/user/message'); ?>
            <div class="block">
                <table class="gridview grid_view_user" width="100%" cellpadding="0" cellspacing="0" border="0">
                    <thead>
                    <tr>
                        <td><input id="check_all" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_id')" /></td>
                        <td><b>ID</b></td>
                        <td><b>Avatar</b></td>
                        <td><b>Tài khoản</b></td>
                        <td><b>Thông tin khác</b></td>
                        <td><b>Người dùng</b></td>
                        <td><b>Thao tác</b></td>
                    </tr>
                    </thead>
                    <tbody>
                        <?php if (count($collection) != 0) : ?>
                        <?php foreach ($collection as $user) : ?>
                            <tr>
                                <input type="hidden" value="" class="edit_url" />
                                <td width="30px" valign="top">
                                    <input class="chk_id" type="checkbox" name="selected[]" value="<?php echo $user->id; ?>" />
                                </td>
                                <td width="30px" valign="top">
                                    <?php echo $user->id; ?>
                                </td>
                                <td width="100px" valign="top">
                                    <?php if (!empty($user->avatar)) :?>
                                    <a target="_blank" href="<?php echo render_src($user->avatar); ?>"><img src="<?php echo render_src($user->avatar); ?>" width="50px" style="vertical-align: middle; border: 2px solid #bbb" /></a>
                                    <?php endif; ?>
                                </td>
                                <td valign="top">
                                    <strong><a <?php if ($has_privilege_view) :?>href="<?php echo site_url('admin/site/user/edit/id/' . $user->id, true); ?>"<?php endif; ?>><?php echo $user->username; ?></a></strong>
                                    <p style="margin-top: 5px;">Online gần đây:  <font style="color: gray;font-style: italic;"><?php echo render_date(get_field($user, 'last_login')); ?></font></p>
                                    <?php if($user->is_online == 1): ?><p style="font-weight: bold;color: gray">Đang offline </p><?php else: ?><p style="font-weight: bold;">Đang online </p><?php endif; ?>
                                    <?php if($user->is_active == 1): ?><p style="font-weight: bold;color: red">Chưa kích hoạt </p><?php else: ?><p style="font-weight: bold;">Đã kích hoạt </p><?php endif; ?>
                                </td>
                                <td valign="top">
                                    <?php if($user->email != ''): ?>   <p>- Email: <?php echo get_field($user, 'email')?></p><?php endif;?>
                                    <?php if($user->yahoo != ''): ?>   <p>- Yahoo: <?php echo get_field($user, 'yahoo')?></p><?php endif;?>
                                    <?php if($user->facebook != ''): ?><p>- Facebook: <?php echo get_field($user, 'facebook')?></p><?php endif;?>
                                    <?php if($user->created_date): ?><p>- Đăng ký ngày: <?php echo render_date(get_field($user, 'created_date')); ?></p><?php endif;?>
                                </td>
                                <td valign="top">
                                    <?php if($user->user_type == 1): ?>  <p>Tra cứu </p><?php elseif($user->user_type == 2): ?><p style="font-weight: bold;">Nghiên cứu </p><?php else: ?><p style="font-weight: bold;color: red">Chuyên gia </p><?php endif; ?>
                                    <?php if($user->phone != ''): ?>     <p>- Điện thoại: <?php echo get_field($user, 'phone')?></p><?php endif;?>
                                    <?php if($user->home_phone != ''): ?><p>- Máy bàn: <?php echo get_field($user, 'home_phone')?></p><?php endif;?>
                                    <?php if($user->address != ''): ?>   <p>- Địa chỉ: <?php echo get_field($user, 'address')?></p><?php endif;?>
                                </td>

                                <td valign="top" width="80px">
                                    <p>
                                        <?php if ($has_privilege_view) :?>
                                        <a class="icon icon_edit" href="<?php echo site_url('admin/site/user/edit/id/' . $user->id, true); ?>"></a>
                                        <?php endif; ?>
                                        <?php if ($has_privilege_delete) :?>
                                        <a class="icon icon_delete" href="<?php echo site_url('admin/site/user/delete/id/' . $user->id, true); ?>" onclick="return confirm('Bạn muốn xóa khoa này?')"></a>
                                        <?php endif; ?>
                                    </p>
                                </td>
                            </tr>
                        <?php endforeach; ?>

                        <?php else : ?>
                            <tr>
                                <td colspan="9" style="padding: 10px">
                                    <p align="center">Danh sách thành viên trống trong thời điểm này hoặc truy vấn tìm kiếm không tìm thấy kết quả, <a href="<?php echo site_url('admin/site/user/filtered_list/' . $return_url, true); ?>">Thử lại</a></p>
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                    <tfoot>

                    </tfoot>
                </table>
            </div>


        <?php if (count($collection) != 0) : ?>
        <?php $paginator = $this->load->view('site/user/paginator', null, true); echo $paginator; ?>
        <?php endif; ?>

    </form>
    </div>
    <?php else :?>
        <?php $this->load->view('layouts/restricted'); ?>
    <?php endif; ?>

<div class="clearfix"></div>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/user/function.js"></script>
<script type="text/javascript">

</script>
